import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import postcssPxToViewport from "postcss-px-to-viewport";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  css: {
    postcss: {
      plugins: [
        postcssPxToViewport({
          unitToConvert: "px", //要转换的单位 px
          viewportWidth: 375, //一倍图
          unitPrecision: 5, //转换后的精度 小数点
          propList: ["*"],
          viewportUnit: "vw", //转换后的单位
          fontViewportUnit: "vw", //转换后的字体单位
          selectorBlackList: [], //选择器黑名单
          minPixelValue: 1, //最小单位
          mediaQuery: true, //媒体查询
          replace: true, //是否替换单位
          exclude: undefined,
          include: undefined,
          landscape: false, //横屏是否适配
          landscapeUnit: "vw",
          landscapeWidth: 568,
        }),
      ],
    },
  },
  server: {
    proxy: {
      // 当匹配到api开头的
      // http://127.0.0.1:5173/api/6666 对应的是
      // https://52coding.cc/yuantiku_api/6666对应
      // 后端接口
      "^/weixin": {
        target: "https://api.weixin.qq.com",
        changeOrigin: true,
        timeout: 1000 * 180,
        // 重写
        rewrite(url) {
          return url.replace(/^\/weixin/, "");
        },
      },
      "^/api": {
        target: "http://192.168.0.221:20145/api",
        // target: "http://127.0.0.1:8000/api",
        changeOrigin: true, //换源
        // 重写
        rewrite(url) {
          return url.replace(/^\/api/, "");
        },
      },
    },
    port: 8080,
  },
});
